package h0708;

import java.util.LinkedList;
import java.util.Scanner;

/**
  * @description 括号匹配
  * @author 不知名帅哥
  * @date 2024/7/8 18:54
  * @version 1.0
*/
public class BracketMatch {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
//        Pattern compile = Pattern.compile("[()]");
//        Matcher matcher = compile.matcher(s);
//        StringBuilder builder = new StringBuilder();
//        while (matcher.find()) {
//            builder.append(matcher.group());
//        }
//        System.out.println(builder);
        //或者
        String res = s.replaceAll("[^()]", "");
        boolean ok=getResult(res);
        System.out.println(ok);
        sc.close();
    }

    private static boolean getResult(String res) {
        LinkedList<Character> stack=new LinkedList<>();
        for (int i = 0; i < res.length(); i++) {
            char c = res.charAt(i);
            if (c=='('){
               stack.addFirst(c);
           }else if (stack.isEmpty()||stack.removeFirst()!='('){
                return false;
            }
        }

        return stack.isEmpty();
    }
}
